<?php
/*
 * Created on 20 mars 2009
 * Created by Ludovic Reenaers
 * lreenaers@hotmail.com
 */


class User{
	private $id;
	private $name;#30
	private $surname;#40
	private $pseudo;#20
	private $email;#255
	private $street;#50
	private $number;#10
	private $zip;#10
	private $city;#50
	private $country;#30
	private $Langue;# obj
	private $ip;#15
	private $ddn;#date
	private $created;#timestamp
	private $last_connected;#timestamp
	private $pws_hash; #32
	private $Profile;
	private $active;#bool

	function __construct($id) {

		if (is_int($id)){
			if($id >= 0){
				$this->id=$id;
			}else{
				throw new FieldFormatException($_SESSION['translator']->idVal);
			}
		}else{
			throw new FieldFormatException($_SESSION['translator']->idInt);
		}
	}
	function setCreated($stamp){
		$this->created = $stamp;
	}
	function setPwsHash($pws,$confirm){

		if ($pws==$confirm){
			if(Validator::validateHash($pws)){
				$this->pws_hash  = $pws;
			}else{

				throw new FieldFormatException($_SESSION['translator']->badHash);
			}
		}else{
			throw new FieldFormatException($_SESSION['translator']->diffPws);
		}
	}
	function setProfile($Profile){
		if($Profile instanceof Profile){
			$this->Profile = $Profile;
		}else{
			throw new FieldFormatException($_SESSION['translator']->reqInstance." Profile");
		}
	}
	function setLastConnected($stamp){
		$this->last_connected = $stamp;
	}
	function setDdn($day,$month,$year){
		#ddn_str ex: 1977/01/22
		if(Validator::validateDate($day,$month,$year)){
			$this->ddn=$year."/".$month."/".$day;
		}else{
			throw new FieldFormatException($_SESSION['translator']->notDate);
		}
	}
	function setActive($bool){
		$this->active = $bool;
	}
	function isActive(){
		return $this->active;
	}
	function setIp($ip){
		 
		if(Validator::validateIp($ip)){
			$this->ip=$ip;
		}
	}
	function setCountry($country){
		if(is_string($country)){
			if(str_replace(" ","",$country) != ""){
				if(strlen($country) > 0 and strlen($country) < 101){
					$this->country  =$country;
				}else{
					throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelCountry);
				}
			}else{
				throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelCountry);
			}
		}else{
			throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelCountry);
		}
	}
	function setCity($city){
		if(is_string($city)){

			if(str_replace(" ","",$city) != ""){
				if(strlen($city) > 0 and strlen($city) < 61){
					$this->city  =$city;
				}else{
					throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelCity);
				}
			}else{
				throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelCity);
			}
		}else{
			throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelCity);
		}
	}
	function setZip($zip){
		if(is_string($zip)){

			if(str_replace(" ","",$zip) != ""){
				if(strlen($zip) > 0 and strlen($zip) < 21){
					$this->zip  =$zip;
				}else{
					throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelZip);
				}
			}else{
				throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelZip);
			}
		}else{
			throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelZip);
		}
	}
	function setBoite($boite){
		if(is_string($boite)){

			if(str_replace(" ","",$boite) != ""){
				if(strlen($boite) > 0 and strlen($boite) < 7){
					$this->boite  =$boite;
				}else{
					throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelBox);
				}
			}else{
				throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelBox);
			}
		}else{
			throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelBox);
		}
	}
	function setNumber($number){
		if(is_string($number)){

			if(str_replace(" ","",$number) != ""){
				if(strlen($number) > 0 and strlen($number) < 11){
					$this->number  =$number;
				}else{
					throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelNumero);
				}
			}else{
				throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelNumero);
			}
		}else{
			throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelNumero);
		}
	}
	function setStreet($street){
		if(is_string($street)){

			if(str_replace(" ","",$street) != ""){
				if(strlen($street) > 0 and strlen($street) < 61){
					$this->street  =$street;
				}else{
					throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelRue);
				}
			}else{
				throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelRue);
			}
		}else{
			throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelRue);
		}
	}
	function setEmail($email){
		if(Validator::validateEmail($email)){
			$this->email=$email;
		}else{
			throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelEmail);
		}
	}
	function setPseudo($pseudo){
		if(is_string($pseudo)){
			if(str_replace(" ","",$pseudo) != ""){
				if(strlen($pseudo) > 0 and strlen($pseudo) < 16){
					$this->pseudo  =$pseudo;
				}else{
					throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelPseudo);
				}
			}else{
				throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelPseudo);
			}
		}else{
			throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelPseudo);
		}
	}
	function setSurname($surname){
		if(is_string($surname)){

			if(str_replace(" ","",$surname) != ""){
				if(strlen($surname) > 0 and strlen($surname) < 61){
					$this->surname =$surname;
				}else{
					throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelPrenom);
				}
			}else{
				throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelPrenom);
			}
		}else{
			throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelPrenom);
		}
	}
	function setName($name){
		if(is_string($name)){

			if(str_replace(" ","",$name) != ""){
				if(strlen($name) > 0 and strlen($name) < 61){
					$this->name =$name;
				}else{
					throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelNom);
				}
			}else{
				throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelNom);
			}
		}else{
			throw new FieldFormatException($_SESSION['translator']->badFormat." ".$_SESSION['translator']->labelNom);
		}
	}
	function setLangue($Langue){

		if(is_a($Langue, "Langue")){
			$this->Langue=$Langue;
		}else{
			throw new FieldFormatException($_SESSION['translator']->reqInstance." Langue");
		}
	}
	function getProfile(){
		return $this->Profile;
	}
	function getId(){
		return $this->id;
	}
	function getName(){
		return $this->name;
	}
	function getSurname(){
		return $this->surname;
	}
	function getPseudo(){
		return $this->pseudo;
	}
	function getEmail(){
		return $this->email;
	}
	function getStreet(){
		return $this->street;
	}
	function getNumber(){
		return $this->number;
	}
	function getBoite(){
		return $this->boite;
	}
	function getZip(){
		return $this->zip;
	}
	function getCity(){
		return $this->city;
	}
	function getCountry(){
		return $this->country;
	}
	function getLangue(){
		return $this->Langue;
	}
	function getIp(){
		return $this->ip;
	}
	function getDdn(){
		return $this->ddn;
	}
	function getCreated(){
		return $this->created;
	}
	function getLastConnected(){
		return $this->last_connected;
	}
	function getPwsHash(){
		return $this->pws_hash;
	}

}
?>

